#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,a[100009][5],p[100009],f[30][30],q[30],sum,r[30],num,ans1,ans2;
void dfs(int s){
     if(s>m)return;
     q[s]=1;
     dfs(s+1);
     sum=0,num=0;
     for(int i=1;i<=m;++i)if(q[m]==1)num++;
     if(num<=ans2)return;
     for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(q[m]==0)continue;
            else if(f[i][j]==1)r[i]=1;
        }
     }
     for(int i=1;i<=n;++i)if(r[i]==1)sum++;
     if(sum==ans1)ans2=max(ans2,num);
     q[s]=0;
     dfs(s+1);
     sum=0,num=0;
     for(int i=1;i<=m;++i)if(q[m]==1)num++;
     if(num<=ans2)return;
     for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(q[m]==0)continue;
            else if(f[i][j]==1)r[i]=1;
        }
     }
     for(int i=1;i<=n;++i)if(r[i]==1)sum++;
     if(sum==ans1)ans2=max(ans2,num);
}
int main(){
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
    cin>>t;
    for(int ii=1;ii<=t;++ii){
        for(int i=1;i<=100001;++i){
            for(int j=1;j<=3;++j){
                a[i][j]=0;
            }
        }
        scanf("%d%d%d%d",&n,&m,&l,&v);
        int c=0,d=0;
        for(int i=1;i<=n;++i){
            scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]);
            if(a[i][3]>0)c=1;
            if(a[i][3]<0)d=1;
        }
        for(int i=1;i<=m;++i)scanf("%d",&p[i]);
        if(c==0&&d==0){
        int ans1=n,ans2=0;
        for(int i=1;i<=n;++i){
            if(a[i][1]>p[m]||a[i][2]<=v)ans1--;
        }
        ans2=m-1;
        printf("%d %d",ans1,ans2);
        }
        else if(c==1&&d==0){
            int ans1=n,ans2=0;
            for(int i=1;i<=n;++i){
                if(a[i][1]>p[i])ans1--;
                else if(a[i][3]==0){
                        if(a[i][2]<=v)ans1--;
                        }
                else{
                    double ti=(v-a[i][2])/a[i][3];
                    double si=a[i][2]*ti+0.5*ti*ti;
                    double sj=a[i][1]+si;
                    if(sj>double(p[m]))ans1--;
                }
            }
            ans2=m-1;
        printf("%d %d\n",ans1,ans2);
        }
        else if(n<=20&&m<=20){
            ans1=n,ans2=0;
            for(int i=1;i<=n;++i){
                if(a[i][3]>0){
                    if(a[i][2]>v){
                        for(int j=m;p[j]>=a[i][1];--j)f[i][j]++;
                    }
                    else{
                        double ti=(v-a[i][2])/a[i][3];
                        double si=a[i][2]*ti+0.5*ti*ti;
                        double sj=a[i][1]+si;
                        if(sj>=double(p[m]))ans1--;
                        for(int j=m;j>=1;--j){
                            if(double(p[j])>sj)f[i][j]++;
                            else break;
                        }
                    }
                }else if(a[i][3]<0&&a[i][2]>v){
                    double ti=(a[i][2]-v)/(0-a[i][3]);
                    double si=a[i][2]*ti-0.5*ti*ti;
                    double sj=a[i][1]+si;
                    for(int j=m;j>=1;j--){
                        if(p[j]>=a[i][1]&&double(p[j]<sj))f[i][j]++;
                        if(p[j]<a[i][1])break;
                    }
                }
                else if(a[i][3]<0&&a[i][2]<=v)ans1--;
            }
            cout<<ans1<<' ';
            dfs(1);
            cout<<ans2<<'\n';
        }
    }
}
